import { ref } from 'vue'

export const mdUdsTb = ref({
  srcDataType: '',
  srcDataAttach: '',

  udsSchemaName: '',
  udsTbName: '',
  udsTbComment: '',
  udsTbLabel: '',
  udsTbCategory: '',
  remarks: '',
  udsFlds: [],
})

export const jsonUdsFld = {
  colName: '',
  colDataType: '',
  colComment: '',
  colLabel: '',
  colKey: false,
  unique: false,
  notNull: false,
  sort: 0,
  remarks: '',
  visible: false
}

export const mdUdsFlds = ref([]
)

export const formFlds = ref({
  fields: [],
})

export const typeOptions = ref([
  { label: '字符串', value: 'varchar' },
  { label: '整型', value: 'int' },
  { label: '布尔值', value: 'bool' },
  { label: '浮点型', value: 'float64' },
  { label: '时间', value: 'time.Time' },
  { label: '枚举', value: 'enum' },
  { label: '单图片（字符串）', value: 'picture' },
  { label: '文件（json字符串）', value: 'file' },
  { label: '多图片（json字符串）', value: 'pictures' }
])
export const typeSearchOptions = ref([
  { label: '=', value: '=' },
  { label: '<>', value: '<>' },
  { label: '>', value: '>' },
  { label: '<', value: '<' },
  { label: 'LIKE', value: 'LIKE' },
  { label: 'BETWEEN', value: 'BETWEEN' },
  { label: 'NOT BETWEEN', value: 'NOT BETWEEN' }
])
export const newField = () => {
  formFlds.value.fields.push(JSON.parse(JSON.stringify(jsonUdsFld)))
}
export const deleteField = (index) => {
  formFlds.value.fields.splice(index, 1)
}
export const moveDownField = (index) => {
  const fCount = formFlds.value.fields.length
  if (index === fCount - 1) {
    return
  }
  const oldDownField = mdUdsFlds.value[index + 1]
  formFlds.value.fields.splice(index + 1, 1)
  formFlds.value.fields.splice(index, 0, oldDownField)
}
export const moveUpField = (index) => {
  if (index === 0) {
    return
  }
  const oldUpField = mdUdsFlds.value[index - 1]
  formFlds.value.fields.splice(index - 1, 1)
  formFlds.value.fields.splice(index, 0, oldUpField)
}

